<?php
require_once '../function/connection.php';

include '../view/user_panel.php';

if (isset($_SESSION['zalogowany'])) {

    connection();

    $sesja = $_SESSION['use_email'];

    // email
    $query1 = "SELECT * FROM `ocena` where `OCE_OSOBA` = '$sesja';";
    $result1 = mysql_query($query1);
    $row1 = mysql_fetch_assoc($result1);
    //echo $row1['OCE_OSOBA'];
    //
    // ocena
    $query2 = "SELECT `OCE_LICZBA` FROM `ocena` WHERE `OCE_OSOBA` = '$sesja'";
    $result2 = mysql_query($query2);
    $row2 = mysql_fetch_assoc($result2);
    //echo $row2['OCE_LICZBA'];
    //
    // komentarz
    $query3 = "SELECT `OCE_KOMENT` FROM `ocena` WHERE `OCE_OSOBA` = '$sesja'";
    $result3 = mysql_query($query3);
    $row3 = mysql_fetch_assoc($result3);
    //echo $row3['OCE_KOMENT'];

    if ($row1) {
        ?>

        <div class="container">

            <p>Już oceniłeś warsztat przyznając mu ocenę: <?php echo $row2['OCE_LICZBA']; ?></p>
            <p>Komentarz jaki dodałeś: <?php echo $row3['OCE_KOMENT']; ?></p>

            <form action="../function/vote.php" method="post" enctype="multipart/form-data"  name="form1">

                <table class="table table-striped table-bordered table-condensed">
                    <tr>
                        <td colspan="2">
                    <center>Jeśli chcesz możesz zmienić swoją opinię na temat naszego serwisu:</center>
                    </td>
                    </tr>
                    <tr>
                        <td>Ocena:</td> 
                        <td> 
                            <select class="tekscik" name="ocena">
                                <option value="1">1</option>
                                <option value="2">2</option>
                                <option value="3">3</option>
                                <option value="4">4</option>
                                <option value="5">5</option>
                                <option value="6">6</option>
                                <option value="7">7</option>
                                <option value="8">8</option>
                                <option value="9">9</option>
                                <option value="10">10</option>                                                    
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td>Komentarz:</td> 
                        <td>
                            <input name="komentarz" class="tekscik" rows="4" cols="25" size="50" type=text value=""/>

                        </td>
                    </tr>

                </table>
                <input name="opcja1" value="Zapisz nową ocenę" class="btn btn-primary" type="submit" /> 
            </form>
        </div>

    <?php } else { ?>

        <div class="container">

            <p> Oceń nasz serwis </p>

            <form action="../function/vote.php" method="post" enctype="multipart/form-data"  name="form1">

                <table class="table table-striped table-bordered table-condensed">
                    <tr>
                        <td colspan="2">
                    <center>Oceń nasz</center>
                    </td>
                    </tr>
                    <tr>
                        <td>Ocena:</td> 
                        <td> 
                            <select class="tekscik" name="ocena">
                                <option value="1">1</option>
                                <option value="2">2</option>
                                <option value="3">3</option>
                                <option value="4">4</option>
                                <option value="5">5</option>
                                <option value="6">6</option>
                                <option value="7">7</option>
                                <option value="8">8</option>
                                <option value="9">9</option>
                                <option value="10">10</option>                                                    
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td>Komentarz:</td> 
                        <td>
                            <input name="komentarz" class="tekscik" rows="4" cols="25" size="50" type=text value=""/>

                        </td>
                    </tr>

                </table>
                <input value="Dodaj ocene" class="btn btn-primary" type="submit" /> 
            </form>
        </div>
        <?php
    }
} else {
    session_start();
    header('Location: /');
    $_SESSION['jgrowl'] = 'Tylko zalogowani użytkownicy mają dostęp do tej cześci strony.';
}

include '../view/footer.php';
?>
